package com.uzai.console.web.locallive;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.common.utils.DateUtil;
import com.uzai.console.dto.device.DeviceQuery;
import com.uzai.console.dto.jd.jdorder.JdOrderIdDto;
import com.uzai.console.dto.user.UserQuery;
import com.uzai.console.dto.wechatprivate.devicewechatinfo.DeviceWechatInfoQuery;
import com.uzai.console.dto.locallive.mtorder.*;
import com.uzai.console.entity.DeviceType;
import com.uzai.console.entity.DeviceWechatInfo;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.mapper.DeviceWechatInfoMapper;
import com.uzai.console.service.device.DeviceService;
import com.uzai.console.service.device.DeviceTypeService;
import com.uzai.console.service.order.OrderReStatusService;
import com.uzai.console.service.order.OrderSourceService;
import com.uzai.console.service.order.OrderStatusService;
import com.uzai.console.service.locallive.MtOrderService;
import com.uzai.console.service.user.UserService;
import com.uzai.console.vo.base.SelectKeyVo;
import com.uzai.console.vo.device.DeviceInfoVo;
import com.uzai.console.vo.order.OrderReStatusVo;
import com.uzai.console.vo.order.OrderStatusVo;
import com.uzai.console.vo.user.UserInfoVo;
import com.uzai.console.vo.wechatprivate.devicewechatinfo.DeviceWechatInfoSelectVo;
import com.uzai.console.vo.locallive.mtorder.MtOrderInfoVo;
import com.uzai.console.vo.locallive.mtorder.MtOrderReportVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 美团订单
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "美团订单",tags = "本地生活|美团订单")
@ApiSort(13)
@RestController
public class MtOrderController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(MtOrderController.class);

    @Autowired
    private MtOrderService mtOrderService;
    @Autowired
    private OrderStatusService orderStatusService;
    @Autowired
    private OrderReStatusService orderReStatusService;
    @Autowired
    private OrderSourceService orderSourceService;
    @Autowired
    private DeviceWechatInfoMapper deviceWechatInfoMapper;
    @Autowired
    private UserService userService;
    @Autowired
    private DeviceTypeService deviceTypeService;
    @Autowired
    private DeviceService deviceService;

    @ApiOperation(value = "查询美团订单列表", notes = "查询美团订单列表", response = MtOrderInfoVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/mtOrder/findMtOrderList")
    public Object findMtOrderList(@RequestBody MtOrderQuery mtOrderQuery){
        return mtOrderService.findMtOrderList(mtOrderQuery);
    }

    @ApiOperation(value = "查询美团订单详情", notes = "查询美团订单详情", response = MtOrderInfoVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/mtOrder/findMtOrderInfo")
    public Object findMtOrderInfo(@RequestBody MtOrderIdDto mtOrderIdDto){
        return mtOrderService.findMtOrderInfo(mtOrderIdDto);
    }

    @ApiOperation(value = "查询美团订单统计信息(总收入、买家总金额、总利润、未绑定用户利润、未收货返利金额）", notes = "查询美团订单统计信息(总收入、买家总金额、总利润、未绑定用户利润、未收货返利金额）", response = MtOrderReportVo.class)
    @ApiOperationSupport(order = 3)
    @PostMapping("/mtOrder/findMtOrderReport")
    public Object findMtOrderReport(@RequestBody MtOrderQuery mtOrderQuery){
        return mtOrderService.findMtOrderRepot(mtOrderQuery);
    }

    @SystemLogType(model = SystemModelEnum.MtOrder, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "订单删除", notes = "订单删除")
    @ApiOperationSupport(order = 4)
    @PostMapping("/mtOrder/delMtOrder")
    public Object delMtOrder(@RequestBody MtOrderDelDto mtOrderDelDto){
        return mtOrderService.delMtOrder(mtOrderDelDto);
    }

    @SystemLogType(model = SystemModelEnum.MtOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "确认收货", notes = "确认收货")
    @ApiOperationSupport(order = 5)
    @PostMapping("/mtOrder/confirmReceive")
    public Object confirmReceive(@RequestBody MtOrderIdDto mtOrderIdDto){
        return mtOrderService.confirmReceive(mtOrderIdDto);
    }

    @SystemLogType(model = SystemModelEnum.MtOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "手动维权", notes = "手动维权")
    @ApiOperationSupport(order = 6)
    @PostMapping("/mtOrder/confirmRefund")
    public Object confirmRefund(@RequestBody MtOrderIdDto mtOrderIdDto){
        return mtOrderService.confirmRefund(mtOrderIdDto);
    }

    @SystemLogType(model = SystemModelEnum.MtOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "订单冻结", notes = "订单冻结")
    @ApiOperationSupport(order = 7)
    @PostMapping("/mtOrder/confirmFrozen")
    public Object confirmFrozen(@RequestBody MtOrderIdDto mtOrderIdDto){
        return mtOrderService.confirmFrozen(mtOrderIdDto);
    }

    @SystemLogType(model = SystemModelEnum.MtOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "订单解冻", notes = "订单解冻")
    @ApiOperationSupport(order = 8)
    @PostMapping("/mtOrder/confirmThaw")
    public Object confirmThaw(@RequestBody MtOrderIdDto mtOrderIdDto){
        return mtOrderService.confirmThaw(mtOrderIdDto);
    }

    @SystemLogType(model = SystemModelEnum.MtOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "解绑用户", notes = "解绑用户")
    @ApiOperationSupport(order = 9)
    @PostMapping("/mtOrder/unbindUser")
    public Object unBindUser(@RequestBody MtOrderUnbindUserDto mtOrderUnbindUserDto){
        return mtOrderService.unbindUser(mtOrderUnbindUserDto);
    }

    @SystemLogType(model = SystemModelEnum.MtOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "绑定用户", notes = "绑定用户")
    @ApiOperationSupport(order = 10)
    @PostMapping("/mtOrder/bindUser")
    public Object bindUser(@RequestBody MtOrderBindUserDto mtOrderBindUserDto){
        return mtOrderService.bindUser(mtOrderBindUserDto);
    }

    @SystemLogType(model = SystemModelEnum.MtOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改解冻时间", notes = "修改解冻时间")
    @ApiOperationSupport(order = 11)
    @PostMapping("/mtOrder/updateThawTime")
    public Object updateThawTime(@RequestBody MtOrderThawTimeDto mtOrderThawTimeDto){
        return mtOrderService.updateThawTime(mtOrderThawTimeDto);
    }

    @ApiOperation(value = "查询机器人下拉列表", notes = "查询机器人下拉列表", response = DeviceInfoVo.class)
    @ApiOperationSupport(order = 12)
    @PostMapping("/mtOrder/findDeviceList")
    public Object findDeviceList(){
        DeviceQuery deviceQuery = new DeviceQuery();
        deviceQuery.setMerId(getLoginInfo().getMerId());
        return deviceService.findDeviceList(deviceQuery);
    }

    @SystemLogType(model = SystemModelEnum.MtOrder, type = OperationTypeEnum.UPLOAD)
    @ApiOperation(value = "手动下载美团订单", notes = "手动下载美团订单")
    @ApiOperationSupport(order = 13)
    @PostMapping("/mtOrder/downloadOrder")
    public Object downloadOrder(@RequestBody MtOrderDownLoadDto mtOrderDownLoadDto){
        mtOrderService.downloadOrder(mtOrderDownLoadDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.MtOrder, type = OperationTypeEnum.UPLOAD)
    @ApiOperation(value = "订单刷新", notes = "订单刷新")
    @ApiOperationSupport(order = 14)
    @PostMapping("/mtOrder/refreshOrder")
    public Object refreshOrder(@RequestBody MtOrderIdDto mtOrderIdDto){
        mtOrderService.refreshOrder(mtOrderIdDto);
        return true;
    }

    @ApiOperation(value = "分页查询会员信息列表", notes = "分页查询会员信息列表", response = UserInfoVo.class)
    @ApiOperationSupport(order = 15)
    @PostMapping("/mtOrder/findUserPage")
    public Object findUserPage(@RequestBody UserQuery userQuery) {
        return userService.findUserPage(userQuery);
    }

    @ApiOperation(value = "查询设备类型下拉列表", notes = "查询设备类型下拉列表", response = SelectKeyVo.class)
    @ApiOperationSupport(order = 16)
    @PostMapping("/mtOrder/findDeiviceTypeListSelect")
    public Object findDeiviceTypeListSelect() {
        return deviceTypeService.findDeviceTypeListSelect();
    }


    @ApiOperation(value = "查询美团订单状态列表", notes = "查询美团订单状态列表", response = OrderStatusVo.class)
    @ApiOperationSupport(order = 17)
    @PostMapping("/mtOrder/getOrderStatusList")
    public Object getOrderStatusList() {
        return orderStatusService.findMtOrderStatusList();
    }

    @ApiOperation(value = "查询美团订单返利状态列表", notes = "查询美团订单返利状态列表", response = OrderReStatusVo.class)
    @ApiOperationSupport(order = 18)
    @PostMapping("/mtOrder/getOrderReStatusList")
    public Object getOrderReStatusList() {
        return orderReStatusService.findMtOrderReStatusList();
    }

    @SystemLogType(model = SystemModelEnum.MtOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "追回返利", notes = "追回返利")
    @ApiOperationSupport(order = 19)
    @PostMapping("/mtOrder/rebateRefound")
    public Object rebateRefound(@RequestBody MtOrderIdDto mtOrderIdDto){
        return mtOrderService.rebateRefound(mtOrderIdDto);
    }
}
